/*
LANG:C++
TASK:nuggets
ID:luongho3
*/
#include <iostream>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("nuggets.in");
ofstream fout("nuggets.out");
#define NPACKOP 11
#define MAX 100000
int packop[NPACKOP],npackop,seq[MAX],seqidx[MAX];
int g,i,cseq,best,best_idx,best_imp;
int suc;
int gcd(int n,int m) {
    if (m==0) return n;
    else return gcd(m,n%m);
}
int main() {
    fin >> npackop;
    for (i=0;i<npackop;++i) {
        fin >> packop[i];
        if (i==0) g = packop[i];
        else g = gcd(g,packop[i]);
    }
    if (g>1) {
       fout << "0\n";
       return 0;
    }
    sort(packop,packop+npackop);
    seq[0] = 0;
    seq[1] = packop[0];
    if (seq[1] == 1) best_imp=0;
    else best_imp = seq[1]-1;
    cseq=1;
    suc=1;
    for (i=0;i<MAX;++i) seqidx[i] = 0;
    while (1) {
          if (cseq==MAX) break;
          best = -1;
          for (i=0;i<npackop;++i) {
              while (packop[i] + seq[seqidx[i]] <= seq[cseq]) {
                    ++seqidx[i];
              }
              if (best==-1 || packop[i] + seq[seqidx[i]] < best) {
                 best = packop[i] + seq[seqidx[i]];
                 best_idx = i;
              }
          }
          seq[++cseq] = best;
          if (seq[cseq]!=seq[cseq-1]+1) {
             suc = 1;
             best_imp = seq[cseq]-1;
          }
          else {
               suc++;
               if (suc==packop[0]) {
                  break;
               }
          }
          seqidx[best_idx]++;          
    }
    fout << best_imp << "\n";
    return 0;
}
